package com.yyfax.ph.personal.authority.bankcard.model;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class BindCardModel extends Model {
	private static final String TAG = BindCardModel.class.getSimpleName();

	public static final int msg_bind_bank = 41;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		switch (functionalCode) {
			case msg_bind_bank:
				return service.bindCard(token, (Card) params);
		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "onNext: " + entity.toString());
		CardResult result = cast(entity);
		EventAgent.post(result);
	}

	private interface Service {
		@POST("account/card/bind")
		Observable<CardResult> bindCard(@Header("token") String token, @Body Card params);
	}

	public static class Card {
		/**
		 * 银行编号
		 */
		public String bankCode;
		/**
		 * 银行卡号，加密
		 */
		public String cardId;
		/**
		 * 身份证号，加密
		 */
		public String certId;
		/**
		 * 姓名
		 */
		public String name;
		/**
		 * 银行预留手机号
		 */
		public String phone;
	}

	public static class CardResult extends BaseResultEntity<ShowCardInfo> {
	}

	public static class ShowCardInfo {
		/**
		 * 银行编号
		 */
		public String bankName;
		/**
		 * 银行卡号，加密
		 */
		public String cardId;
		/**
		 * 姓名
		 */
		public String name;
		/**
		 * 银行编号
		 */
		public String bankCode;
	}
}
